package com.dofast.bt.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dofast.bt.R;
import com.dofast.bt.base.BaseApplication;
import com.dofast.bt.bean.GoodsBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * username:Created by hsj on 2016/12/22 0022.
 * class：
 * 类描述：收藏的宝贝
 */

public class MessageListAdapter extends BaseAdapter {
    private List<GoodsBean> list = new ArrayList<GoodsBean>();
    private SelectCallBack callBack;

    public MessageListAdapter(List<GoodsBean> list) {
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            convertView = LayoutInflater.from(BaseApplication.getInstance().getApplicationContext()).inflate(R.layout.item_collect_goods, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.llDelete.setVisibility(View.GONE);
        //姓名
        holder.tvName.setText(list.get(position).getName());
        //消息
        holder.tvPrice.setTextColor(Color.rgb(123, 123, 123));
        holder.tvPrice.setText(list.get(position).getContent() );
        //头像
        Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getImg_head()).placeholder(R.mipmap.head_1).into(holder.ivPhoto);

        if (position == 0) {
            Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getImg_head()).placeholder(R.mipmap.head_6).into(holder.ivPhoto);
            holder.ivDot.setVisibility(View.VISIBLE);
        }
        if (position == 1) {
            Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getImg_head()).placeholder(R.mipmap.head_1).into(holder.ivPhoto);

        }
        if (position == 2) {
            Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getImg_head()).placeholder(R.mipmap.head_2).into(holder.ivPhoto);
            holder.ivDot.setVisibility(View.VISIBLE);
        }
        if (position == 3) {
            Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getImg_head()).placeholder(R.mipmap.head_3).into(holder.ivPhoto);

        }
        if (position == 4) {
            Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getImg_head()).placeholder(R.mipmap.head_4).into(holder.ivPhoto);
            holder.ivDot.setVisibility(View.VISIBLE);
        }
        if (position == 5) {
            Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getImg_head()).placeholder(R.mipmap.head_5).into(holder.ivPhoto);

        }
        if (position == 6) {
            Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getImg_head()).placeholder(R.mipmap.head_6).into(holder.ivPhoto);

        }

        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.iv_photo)
        ImageView ivPhoto;
        @BindView(R.id.iv_dot)
        ImageView ivDot;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.ll_delete)
        LinearLayout llDelete;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
